# 使用多阶段构建
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# 复制解决方案文件
COPY ["Terra.sln", "./"]
COPY ["Directory.Build.props", "./"]
COPY ["Directory.Packages.props", "./"]

# 复制项目文件
COPY ["src/server/Terra.Core/Terra.Core.csproj", "src/server/Terra.Core/"]
COPY ["src/server/Terra.Data/Terra.Data.csproj", "src/server/Terra.Data/"]
COPY ["src/server/Terra.Service/Terra.Service.csproj", "src/server/Terra.Service/"]
COPY ["src/server/Terra.WebApi/Terra.WebApi.csproj", "src/server/Terra.WebApi/"]

# 还原NuGet包
RUN dotnet restore

# 复制所有源代码
COPY ["src/server/Terra.Core/", "src/server/Terra.Core/"]
COPY ["src/server/Terra.Data/", "src/server/Terra.Data/"]
COPY ["src/server/Terra.Service/", "src/server/Terra.Service/"]
COPY ["src/server/Terra.WebApi/", "src/server/Terra.WebApi/"]

# 发布应用
WORKDIR "/src/src/server/Terra.WebApi"
RUN dotnet publish "Terra.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false

# 最终镜像
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

# 设置环境变量
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:80

# 暴露端口
EXPOSE 80

ENTRYPOINT ["dotnet", "Terra.WebApi.dll"] 